//
//  DetailsTableViewCell.m
//  Fragrance
//
//  Created by mark on 15/5/23.
//  Copyright (c) 2015年 dllo. All rights reserved.
//

#import "DetailsTableViewCell.h"
#import <UIImageView+AFNetworking.h>

@implementation DetailsTableViewCell

- (void)dealloc
{
    [_nameLabel release];
    [_model release];
    [_shopNameLabel release];
    [_favoriteNumLabel release];
    [_chefIcon release];
    [_favoritePersonLabel release];
    [_introduceLabel release];
    [_myScrollView release];
    [_model release];
    [_descLabel release];
    [super dealloc];
    
    
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self CreateDetaisCell];
    }
    return self;
}

- (void)CreateDetaisCell
{
    self.goodsIconOne = [[[UIImageView alloc] init] autorelease];
    [self.contentView addSubview:self.goodsIconOne];
    
    self.nameLabel = [[[UILabel alloc] init] autorelease];
    [self.contentView addSubview:self.nameLabel];
    
    self.favoriteNumLabel = [[[UILabel alloc] init] autorelease];
    [self.contentView addSubview:self.favoriteNumLabel];
    self.favoritePersonLabel = [[[UILabel alloc] init] autorelease];
    [self.contentView addSubview:self.favoritePersonLabel];
    
    self.chefIcon = [[[UIImageView alloc] init] autorelease];
    [self.contentView addSubview:self.chefIcon];
    
    self.shopNameLabel = [[[UILabel alloc] init] autorelease];
    [self.contentView addSubview:self.shopNameLabel];
    
    self.introduceLabel = [[[UILabel alloc] init] autorelease];
    [self.contentView addSubview:self.introduceLabel];
    
    self.descLabel = [[[UILabel alloc] init] autorelease];
    [self.contentView addSubview:self.descLabel];
    
    self.myScrollView = [[[UIScrollView alloc] init] autorelease];
    [self.contentView addSubview:self.myScrollView];
    
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    self.nameLabel.frame = CGRectMake(40, 170, 220, 30);
    self.nameLabel.textAlignment = 1;
    self.nameLabel.backgroundColor = [UIColor clearColor];

    self.favoriteNumLabel.frame = CGRectMake(180, 190, 50, 30);
    self.favoriteNumLabel.textAlignment = 2;
    self.favoriteNumLabel.backgroundColor = [UIColor clearColor];
    self.favoritePersonLabel.text = @"人想吃";
    self.favoritePersonLabel.frame = CGRectMake(230, 190, 100, 30);
    self.favoritePersonLabel.backgroundColor = [UIColor clearColor];
    
    self.chefIcon.frame = CGRectMake(120, 200, 60, 60);
    self.chefIcon.backgroundColor = [UIColor redColor];
    self.chefIcon.layer.cornerRadius = 30;
    self.chefIcon.layer.masksToBounds = YES;
    
    self.shopNameLabel.frame = CGRectMake(110, 260, 150, 40);
    self.shopNameLabel.backgroundColor = [UIColor clearColor];
    
    self.introduceLabel.frame = CGRectMake(110, 280, 100, 40);
    self.introduceLabel.text = @"美食介绍";
    self.introduceLabel.backgroundColor = [UIColor clearColor];
    
    self.descLabel.frame = CGRectMake(10, 310, self.frame.size.width - 20, 30);
    self.descLabel.backgroundColor = [UIColor clearColor];
    self.descLabel.font = [UIFont systemFontOfSize:20.0];
    self.descLabel.numberOfLines = 10;
    [self.descLabel sizeToFit];
    
    self.myScrollView.frame = CGRectMake(10, 10, self.frame.size.width, 150);
    self.myScrollView.showsVerticalScrollIndicator = NO;
    self.myScrollView.showsHorizontalScrollIndicator = NO;
    self.myScrollView.pagingEnabled = YES;
    self.myScrollView.bounces = NO;
    self.myScrollView.delegate = self;
    
    
    
    
}

- (void)setModel:(CftModelData *)model
{
    self.nameLabel.text = model.name;
    self.shopNameLabel.text = model.shopName ;
    self.descLabel.text = model.desc;
    self.favoriteNumLabel.text = model.favoriteNum;
    for (int i = 0 ; i < model.picListarrayData.count; i++) {
        PicListModelData *model1 = [model.picListarrayData objectAtIndex:i];
        CGFloat height = [AutoHeight getLabelHight:20.0 :self.frame.size.width - 20 :model.desc];
        UIImageView *image = [[UIImageView alloc] initWithFrame:CGRectMake(10, 340 + height - 30 + i * 160, self.frame.size.width - 20, 150)];

        [image setImageWithURL:[NSURL URLWithString:model1.picListThumbUrl] placeholderImage:nil];
        [self.contentView addSubview:image];
        [image release];
    }
    
    [self.chefIcon setImageWithURL:[NSURL URLWithString:model.chefIconUrl] placeholderImage:nil];
    
    for (int i = 0 ; i < model.picListarrayData.count; i++) {
        PicListModelData *model1 = [model.picListarrayData objectAtIndex:i];
        
        UIImageView *mImageView = [[UIImageView alloc] initWithFrame:CGRectMake(self.frame.size.width  * i, 0, self.frame.size.width - 20 , 150 )];
        
        [mImageView setImageWithURL:[NSURL URLWithString:model1.picListThumbUrl] placeholderImage:nil];
        mImageView.contentMode = UIViewContentModeScaleAspectFill;
        mImageView.userInteractionEnabled = YES;
        [self.myScrollView addSubview:mImageView];
        [mImageView release];
    }
    
    self.myScrollView.contentSize = CGSizeMake(self.frame.size.width  * model.picListarrayData.count, 150);
    
    
    page = [[UIPageControl alloc] initWithFrame:CGRectMake(100, self.frame.size.height + 80, 100, 40)];
    
    page.currentPage = 0;
    page.currentPageIndicatorTintColor = [UIColor blueColor];
    page.numberOfPages = model.picListarrayData.count;
    [self.contentView addSubview:page];
    [page release];


}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    NSInteger i = scrollView.contentOffset.x / self.frame.size.width;
    page.currentPage = i;
}



- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
